import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
import side from '@/components/side';
import index from '@/view/index/index';
import login from '@/view/login/index';
import staff from '@/view/staff/index';
import publics from '@/view/public/index';

import run from '@/view/run/index';
import department from '@/view/department/index';
import log from '@/view/log/index';


Vue.use(Router)
const routes = [

  {
    path: '/login',
    name: 'login',
    meta: {
      noAuth: true
    },
    component: login,
  },
  {
    path: '/',
    name: 'side',
    redirect: '/index', // 路由重定向
    component: side,
    children: [{
        path: '/index',
        name: 'index',
        component: index,
      },
      {
        path: '/public',
        name: 'public',
        component: publics,
      },
      {
        path: '/staffManage',
        name: 'staffManage',
        component: staff,
      },
      {
        path: '/run',
        name: 'run',
        component: run,
      },
      {
        path: '/department',
        name: 'department',
        component: department,
      },
      {
        path: '/log',
        name: 'log',
        component: log,
      }



    ]
  }
]



const router = new Router({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  if (to.meta.noAuth) return next()
  if (!store.state.userInfo) return next('/login')

  next()
})


export default router
